<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace App\Http\Models\Student;

/**
 * Description of CourseBooking
 *
 * @author Jinfeihu
 */

use Illuminate\Database\Eloquent\Model;

class CourseBooking extends Model
{

    public $timestamps = false;
    protected $table = "course_booking";
    protected $fillable = [
        'id',
        'student_id',
        'dances_id',
        'status',
        'created_at',
        'teacher_id',
        'clear_at',
        'begin_time',
        'end_time',
        'types',
        'dance'
    ];

    //获取学员信息
    public function getStudentBelongsTo()
    {
        return $this->belongsTo('App\Http\Models\Student\Student', 'student_id', 'id');
    }

    //获取教练信息
    public function getUserBelongsTo()
    {
        return $this->belongsTo('App\Http\Models\User\User', 'teacher_id', 'id');
    }

    //获取课程信息
    public function getDancesBelongsTo()
    {
        return $this->belongsTo('App\Http\Models\Dances\Dances', 'dance', 'id');
    }

    /**
     * 获取用户预约信息
     * @param int $studentId 学员ID
     * @param int $beginTime 预约当天开始时间
     * @param int $endTime 预约当天结束时间
     * @param int $types 类型 0团课、1私教
     * @param int $dancesId 课程id
     */
    public static function getStudentCourse($studentId, $beginTime, $endTime, $types, $dancesId)
    {
        return self::query()->where([
            'student_id' => $studentId,
            'types'      => $types,
            'status'     => 0,
        ])->where('end_time', '>=', $beginTime)->where('end_time', "<=", $endTime)->orderBy('created_at', 'desc')->first();
    }
    public static function getPrivateStudentCourse($studentId, $beginTime, $endTime, $types, $teacherId)
    {
        return self::query()->where([
            'student_id' => $studentId,
            'types'      => $types,
            'status'     => 0,
            'teacher_id'=>$teacherId
        ])->where('end_time', '>=', $beginTime)->where('end_time', "<=", $endTime)->orderBy('created_at', 'desc')->first();
    }
    /**
     * 获取用户所有预约信息
     * @param int $studentId 学员ID
     * @param int $dancesId 课程ID
     * @param int $teacherId 教练ID
     */
    public static function getStudentCourseAll($studentId, $dancesId, $teacherId)
    {
        return self::query()->where([
            'student_id' => $studentId,
            'dances_id'  => $dancesId,
            'teacher_id' => $teacherId,
            'status'     => 0
        ])->get()->toArray();
    }
}
